/*
Author:kermit
Email:455196886@qq.com
Company:http://dragontrail.com/
Creattime:2016-12-03
*/

// 依赖jquery,resLoader,swiper



//项目的主函数
var App = function(){
	var app = this;
	app.screenWidth = $(window).width();
	app.screenHeight = $(window).height();
	app.unit = app.screenWidth/750;//设计稿宽750px
	//加载资源
	app.Loader = new resLoader({
		resources : [
			'imgs/loading.gif',
			'imgs/loading_car.png'
		],
		onStart : function(total){},
		onProgress : function(current, total){},
		onComplete : function(total){
			app.AfterLoad();
			app.WindowResize();
		}
	})
	//背景音乐的控制
	app.BgMusic = (function(){
		var bgMusic = {};
		bgMusic.musicBtn = $("#bg-music");
		bgMusic.music = bgMusic.musicBtn.find('#music')[0];
		bgMusic.play = function(){
			if(bgMusic.music.paused){bgMusic.music.play();}
			bgMusic.musicBtn.addClass('bg-music-ani').removeClass('bg-music-pause');
		}
		bgMusic.pause = function(){
			if(!bgMusic.music.paused){bgMusic.music.pause();}
			bgMusic.musicBtn.addClass('bg-music-pause').removeClass('bg-music-ani');
		}
		bgMusic.musicBtn.click(function(){
			var pause = $(this).hasClass('bg-music-pause') ? true : false;
			pause ? bgMusic.play() : bgMusic.pause();
		});
		return bgMusic;
	})();
	//加载后的处理
	app.AfterLoad = function(){
		$('#loading').hide();
		$('#main').show();
		app.BgMusic.play();
	}
	//窗口变化
	app.WindowResize = function(){
		$(window).resize(function(event){
			app.screenWidth = $(window).width();
			app.screenHeight = $(window).height();
			app.unit = app.screenWidth/750;
			//console.log('WindowResize',app.screenWidth,app.screenHeight);
		});
	}

}
var NewApp = new App();
NewApp.Loader.start();











